﻿var url = new Url();
var $Id = url.GetQueryString("orderId");
var $css = new Url().GetQueryString("css");
$(".queding_xia").hide();
//退回
$(".back").click(function () {
    $(".queding").hide();
    $(".queding_xia").slideDown(500);
});
$(".return").click(function () {
    $(".reason").val("");
    $(".queding").show();
    $(".queding_xia").slideUp(500);
});

var $Id = url.GetQueryString("orderId");
$.getJSON(//绑定订单
        "../Handler/FinancialOrder.ashx",
        { Id: $Id, type: 4, _: Math.random() },
        function (result) {
            if (result.Status) {
                if (result.Data.Order.ContractStartDate == "") {
                    $(".startDate").css('display', 'none');
                }
                if (result.Data.Order.ContractEndDate == "") {
                    $(".endDate").css('display', 'none');
                }

                $("#orderData div[data-name]").each(function (index, item) {
                    $(this).text(result.Data.Order[$(this).attr("data-name")]);
                });
                $(".IsSameBank").text((result.Data.Order.IsSameBank ? "是" : "否"));
                if (!result.Data.Order.IsSameBank) {
                    $("div.transferBank").css("display", "block");
                }
                $(".divEndDateTitle").html(GetEndDateName(result.Data.Order.PTypeId));

                $("div[data-plan='IsFortunePlan']").text((result.Data.Order.IsFortunePlan ? "是" : "否"));

                if (result.Data.Order.VerifyStatus == 3) {
                    $("#backTitle").css("display", "inline");
                    $("#backReason").text(result.Data.Order.VerifyMemo);
                }
                if (result.Data.User) {
                    $("#userData div[data-name]").each(function (index, item) {
                        $(this).text(result.Data.User[$(this).attr("data-name")]);
                    });
                }
            }
            else {
                alert(result.Message);
            }
        }
    );


//加载合同列表
$.getJSON("../Handler/FileHandler.ashx", { OrderId: $Id, type: 2, _: Math.random() }, function (result) {
    $(".contract_list").empty();//清空合同列表
    if (result != null && result != "") {
        //绑定模板
        $.each(result, function (index, item) {
            $("#fileTemplate").tmpl(item).appendTo($(".contract_list"));
        });
        //预览
        $(".preview").css("cursor", "pointer").click(function () {
            $("#imgView").attr("src", $(this).attr("data-link"));
        });
    }
    else {
        $(".contract_list").text("暂没有相关文件！");
    }
});
//通过
$(".queding .pass").click(function () {
    if (confirm("确定要通过审核本合同？")) { 
        $.getJSON("../Handler/FinancialOrder.ashx", { Id: $Id, type: 12, _: Math.random() }, function (result) {
            alert(result.Message);
            if (result.Status) {
                location.href = "ContractManageList.aspx?css=1026";
                //location.href = "CreditMatch.aspx?orderId=" + $Id + "&css=1010";
            }
        })
    }
});
//提交
$(".submit").click(function () {
    if (confirm("确定要退回本合同？")) {
        var $reason = $(".reason").val();
        $.getJSON("../Handler/FinancialOrder.ashx", { Id: $Id, type: 13, Reason: $reason, _: Math.random() },
            function (result) {
                alert(result.Message);
                if (result.Status) {
                    location.href = "ContractManageList.aspx?css=1026";
                    //location.href = "ContractManageList.aspx?css=" + $css;
                }
            })
    }
});
//伸缩图片
var isMax = false;
var i = 500;
window.onmousewheel = function (e) {
    e = e || window.event;
    var scrollValue = 0;
    if (e.wheelDelta) {//IE/Opera/Chrome 
        scrollValue = e.wheelDelta;
    } else if (e.detail) {//Firefox 
        scrollValue = e.detail;
    }
    $("#imgView").width(i);
    $("#myModal").scrollLeft(i);
    if (scrollValue > 0) {
        i = i + 20;
        if (i > 1500) {
            i = 1500;
        }
    }
    else {
        i = i - 20;
        if (i < 500) {
            i = 500;
            $(".modal-content").width(200);
        }
    }
}

//结束日期标题
function GetEndDateName($Id) {
    var product = new Product();
    var entity = product.GetInfoById($Id);
    if (entity != null) {
        if (entity.FinancialMode == 1) {
            return "封闭结束日期：";
        }
        else {
            return "合同结束日期：";
        }
    }
    else {
        return "合同结束日期：";
    }
}
